#!/bin/bash

# Builds NSIS installer for Windows in Docker.

#
# Note!!: It would be possible to generate the NSIS installer with CPack,
# but let's use the old packaging scripts for now and only build with CMake.
#

DUSTRAC_RELEASE_VERSION=2.1.1

CMAKE=/mxe/usr/bin/i686-w64-mingw32.static-cmake
CPACK=/mxe/usr/bin/i686-w64-mingw32.static-cpack

CMD="export LANG=en_US.UTF-8 && \
     export LC_ALL=en_US.UTF-8 && \
     export PATH='$PATH':/mxe/usr/bin && \
     cd /dr2d && rm -rf build-windows-nsis && mkdir -p build-windows-nsis && \
     cd build-windows-nsis && ${CMAKE} -DPACKAGE_TYPE=NSIS .. && \
     make -j4 && \
     DUSTRAC_RELEASE_VERSION=${DUSTRAC_RELEASE_VERSION} ../scripts/build-windows-nsis-packaging-helper"

if [ -f /.dockerenv ]; then
    echo "Script inside Docker"
    bash -c "${CMD}"
else
    echo "Script outside Docker"
    docker run --user $(id -u):$(id -g) --privileged -t -v $(pwd):/dr2d juzzlin/mxe-qt5-20.04:latest bash -c "${CMD}"
fi

